<?php

namespace app\admin\validate;

use app\common\validate\jy\ProfitSharing as ParentProfitSharing;

class ProfitSharing extends ParentProfitSharing
{
	/**
     * 验证规则
     */
    protected $rule = [
        'id'          => 'require|isProfitSharing|isProfitSharinged'
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'id.require'           => '订单ID不能为空',
        'id.isProfitSharing'   => '订单状态不可分账',
        'id.isProfitSharinged' => '订单已经分帐'
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'profit_sharing' => ['id']
    ];

    //是否属于分账状态
    protected function isProfitSharing($value, $rule, $data = []) {
        $row = loadOnly('Base')->get('jy_order__' . $value, function($id) {
            return loader('admin')->loadModel('jy\\Order')->find($id);
        }, [$value]);
        if(empty($row)) {
            return false;
        }
        return $row['is_profit_sharing'];
    }

    //是否已经分帐
    protected function isProfitSharinged($value, $rule, $data = []) {
        $row = loadOnly('Base')->get('jy_order__' . $value, function($id) {
            return loader('admin')->loadModel('jy\\Order')->find($id);
        }, [$value]);
        if(empty($row)) {
            return false;
        }
        return !$row['profit_sharing'];
    }
}